using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Entities;
using Utility;

namespace BUS
{
   public class tbTraloiBUS
    {
        public static void Insert(tbTraloi tl)
        {
            tbTraloiDAL tlDAL = new tbTraloiDAL();
            tlDAL.Insert(tl);
        }
        public static void Update(tbTraloi tl)
        {
            tbTraloiDAL tlDAL = new tbTraloiDAL();
            tlDAL.Update(tl);
        }
        public static void Delete(int iD)
        {
            tbTraloiDAL tlDAL = new tbTraloiDAL();
            tlDAL.Delete(iD);
        }
        public static tbTraloiCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbTraloiDAL tlDAL = new tbTraloiDAL();
            return tlDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbTraloiCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbTraloiDAL tlDAL = new tbTraloiDAL();
            return tlDAL.Get(cri.Criter, 0, 0, tbTraloiCollumn.Matrl.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbTraloi GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbTraloiCollumn.Matrl.ToString(), Condition.EQUAL, iD);
            tbTraloiDAL tlDAL = new tbTraloiDAL();
            tbTraloiCollection tlCollection = tlDAL.Get(cri.Criter, 0, 0, tbTraloiCollumn.Matrl.ToString(), OrderDirection.ASC.ToString(), out total);
            if (tlCollection.Count > 0)
                return tlCollection[0];
            return null;
        }
        public static tbTraloiCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbTraloiDAL tlDAL = new tbTraloiDAL();
            return tlDAL.Get(cri.Criter, 1, number,
             tbTraloiCollumn.Matrl.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbTraloiCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbTraloiDAL tlDAL = new tbTraloiDAL();
            return tlDAL.Get(cri.Criter, 1, number,
               tbTraloiCollumn.Matrl.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}

